<?php 
require_once "config.php";
require_once 'class/class.phpmailer.php';




//$link = "http://hotwo.indisil.com/listing.php?offer_prefix=helengeli-island-offer";
//if (isset($_POST['submit'])){
    $enc_member_id='';
    $error_msg=array();
    //echo(":".$_POST["to_email"].";");
    $fname=isset($_POST['firstname'])?$_POST['firstname']:'';
    $lname=isset($_POST['lastname'])?$_POST['lastname']:'';
    $email=isset($_POST['email'])?$_POST['email']:'';
    $dsc=isset($_POST['description'])?$_POST['description']:'';
    //echo "<br> to:".$to."<br>";
    $site_link=$_SERVER['HTTP_HOST'];
    if (isset($_SESSION['member_id'])){
        $en_key='Oi56TCVH@#%^&*TFf78@hey@2';
        $enc = new Encryption();
        //echo "<br>member_id: ".$_SESSION['member_id'];
        $enc_member_id = $enc->encrypt($en_key, $_SESSION['member_id']);
    }
        //echo "<br> from_error:".$error_msg["from_error"];
        //if(!isset($error_msg["from_error"])){            
            if (strlen($enc_member_id)>0){
                $site_link.="?k=".$enc_member_id;
            }
            $personal_msg=!empty($dsc)?"<div style='border: 1px solid #ccc'> Personal message from {$_SESSION['first_name']} {$_SESSION['last_name']}: {$dsc}</div>":"";
            $body = "<p>Hi {$fname},</p>
                <p>{$_SESSION['first_name']} {$_SESSION['last_name']}has just sent you an invitation to <a href='http://hotelswithoffers.com/'>hotelswithoffers.com</a>. 
                <a href='{$site_link}'>Click here</a> to find the best deals to things happening around you. <br>
                {$personal_msg}
                <p>Team HWO.</p>
                ";
            //echo "<br>enc_member_id: ".$enc_member_id;
            $mail = new PHPMailer();
            //$mail->HeaderLine('Content-type', 'text/html');
            $mail->IsHTML(true);
            $mail->AddAddress($email);
            if (strlen($_SESSION['member_email'])>0){
                $mail->From = $_SESSION['member_email'];
            }
            $mail->Subject = "{$_SESSION['first_name']} {$_SESSION['last_name']} has invited you to hotelswithoffers.com";
            $mail->Body = $body;
            
            ?>
            <form method="post" action="invitations.php" name="form1" id="form1">
            <?php
            if ($mail->Send()){
                //$error_msg["send_error"]="There has been an error sending the email to ".$to;
                ?>                
                <input type="hidden" name="err_msg" value="success" />                          	
                <?php
                //echo "There has been an error sending the email to ".$to;
                
            }  else {
                ?>
                <input type="hidden" name="err_msg" value="fail" /> 
                <?php
                //$error_msg["send_error"]="Your mail has been successfully sent";
//                $return_arr["success"]= false;
//                echo json_encode($return_arr);
                //echo "Your mail has been successfully sent";
            }    
            ?>
            </form>
            <script type="text/javascript">
                document.form1.submit(); 
            </script> 
            <?php
        //}
    //}
    
//}

?>
